package com.modularity.camera.basic.base;

import androidx.fragment.app.Fragment;

import com.modularity.camera.basic.annotation.KeepNotProguard;
import com.modularity.camera.basic.bean.Size;
import com.modularity.camera.basic.enums.CameraQuality;
import com.modularity.camera.basic.listener.ICBMessageReportListener;
import com.modularity.camera.basic.listener.ICBTakePictureListener;

import java.util.List;

@KeepNotProguard
public abstract class CameraFragment extends Fragment {

    private final int DEFAULT_WIDTH = 1920;
    private final int DEFAULT_HEIGHT = 1080;
    private boolean customPreview = false;
    private boolean customPicture = false;
    private boolean customRotate = false;
    private boolean customScaleX = false;
    private boolean customScaleY = false;

    private Size customPreviewSize = new Size(DEFAULT_WIDTH, DEFAULT_HEIGHT);
    private Size customPictureSize = new Size(DEFAULT_WIDTH, DEFAULT_HEIGHT);
    private float rotateValue = 0f;
    private float scaleX = 0f;
    private float scaleY = 0f;
    public CameraQuality cameraQuality = CameraQuality.QUALITY_HIGH;
    public ICBMessageReportListener messageReportListener;

    public abstract void takePicture(String fileName, ICBTakePictureListener listener);

    public abstract void takePicture(ICBTakePictureListener listener);

    public abstract void switchCamera();

    public abstract void releaseCamera();

    public void setCameraQuality(CameraQuality cameraQuality) {
        this.cameraQuality = cameraQuality;
    }

    public void setMessageReportListener(ICBMessageReportListener messageReportListener) {
        this.messageReportListener = messageReportListener;
    }

    public abstract List<Size> supportedPreviewSizes();

    public abstract List<Size> supportedPictureSizes();

    public void setCustomPicture(boolean picture, Size size) {
        this.customPicture = picture;
        this.customPictureSize = size;
    }

    public void setCustomRotate(boolean isRotate, int value) {
        this.customRotate = isRotate;
        this.rotateValue = value;
    }

    public void setCustomScaleX(boolean flag,float scaleX){
        this.scaleX = scaleX;
        this.customScaleX = flag;
    }
    public void setCustomScaleY(boolean flag,float scaleY){
        this.scaleY = scaleY;
        this.customScaleY = flag;
    }


    public void setCustomPreview(boolean preview, Size size) {
        this.customPreview = preview;
        this.customPreviewSize = size;
    }

    public Size getCustomPictureSize() {
        return customPictureSize;
    }

    public Size getCustomPreviewSize() {
        return customPreviewSize;
    }

    public boolean isCustomPreview() {
        return customPreview;
    }

    public boolean isCustomPicture() {
        return customPicture;
    }

    public boolean isCustomRotate(){
        return  customRotate;
    }

    public boolean isCustomScaleX() {
        return customScaleX;
    }

    public boolean isCustomScaleY() {
        return customScaleY;
    }

    public float getRotateValue(){
        return rotateValue;
    }

    public float getScaleX(){
        return scaleX;
    }

    public float getScaleY() {
        return scaleY;
    }

    public void messageReport(String message) {
        if (messageReportListener != null) {
            messageReportListener.onMessageReport(message);
        }
    }
}
